cmake_minimum_required(VERSION 3.8)

project(video_player)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_definitions(-Wall -Werror)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# --------------------------
#  依赖
# --------------------------

# 使用ament_cmake_auto简化ROS 2依赖管理
find_package(ament_cmake_auto REQUIRED)
ament_auto_find_build_dependencies()

# 添加OpenCV依赖
find_package(OpenCV REQUIRED COMPONENTS core videoio imgproc highgui)

# --------------------------
#  构建
# --------------------------

# 生成共享库
ament_auto_add_library(${PROJECT_NAME} SHARED
  src/video_player_node.cpp  # 视频节点核心代码
)

# 指定头文件搜索路径
target_include_directories(${PROJECT_NAME} PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>  # 编译时头文件路径
  $<INSTALL_INTERFACE:include>                            # 安装后头文件路径
  ${OpenCV_INCLUDE_DIRS}  
)

target_link_libraries(${PROJECT_NAME} 
  ${OpenCV_LIBS}  
)


# --------------------------
# 注册组件化节点
# --------------------------

rclcpp_components_register_node(${PROJECT_NAME}
  PLUGIN "video_player::VideoPlayerNode"  # 视频节点完整类名（命名空间+类名）
  EXECUTABLE ${PROJECT_NAME}_node         # 可执行文件名（如 mindvision_camera_node，可自定义）
)


# --------------------------
#  测试
# --------------------------

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  list(APPEND AMENT_LINT_AUTO_EXCLUDE
    ament_cmake_copyright
    ament_cmake_cpplint
    ament_cmake_uncrustify
  )
  ament_lint_auto_find_test_dependencies()

  ament_cpplint(EXCLUDE ${_linter_excludes})
endif()


# --------------------------
# 安装配置
# --------------------------

# 安装库文件
install(TARGETS ${PROJECT_NAME}
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION bin
)

# 安装头文件
install(DIRECTORY include/
  DESTINATION include/${PROJECT_NAME}
)

# 安装配置和启动文件
install(DIRECTORY
  config  # 包含 camera_info.yaml 和 demo.avi（视频文件放这里）
  launch  
  DESTINATION share/${PROJECT_NAME}
)

ament_package()